local shoucheng = fk.CreateSkill {

  name = "joy__shoucheng",

  tags = {  },

}



shoucheng:addEffect(fk.AfterCardsMove, {
  name = "joy__shoucheng",
  anim_type = "support",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(shoucheng.name) or player:usedSkillTimes(shoucheng.name, Player.HistoryTurn) > 0 then return end
    for _, move in ipairs(data) do
      if move.from then
        local from = player.room:getPlayerById(move.from)
        if from:getHandcardNum() < from.hp and from.phase == Player.NotActive and not from.dead then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
              return true
            end
          end
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local targets = {}
    local room = player.room
    for _, move in ipairs(data) do
      if move.from then
        local from = room:getPlayerById(move.from)
        if from:getHandcardNum() < from.hp and from.phase == Player.NotActive and not from.dead then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
              table.insertIfNeed(targets, from.id)
              break
            end
          end
        end
      end
    end
    if #targets == 0 then return end
    if #targets > 1 then
      local tos = player.room:askForChoosePlayers(player, targets, 1, 1, "#joy__shoucheng-choose", shoucheng.name, true)
      if #tos > 0 then
        event:setCostData(self, tos[1])
        return true
      end
    else
      event:setCostData(self, targets[1])
      return player.room:askForSkillInvoke(player, shoucheng.name, nil, "#joy__shoucheng-draw::" .. targets[1])
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(event:getCostData(self))
    room:doIndicate(player.id, {to.id})
    player:broadcastSkillInvoke("shoucheng")
    to:drawCards(2, shoucheng.name)
  end,
})

return shoucheng